package com.hb0730.boot.admin.modules.sci.controller;

import com.hb0730.boot.admin.base.R;
import com.hb0730.boot.admin.data.domain.BasePage;
import com.hb0730.boot.admin.modules.sci.model.entity.SciMessage;
import com.hb0730.boot.admin.modules.sci.service.SciMessageService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sci/msg")
@RequiredArgsConstructor
public class SciMessageController {
    private final SciMessageService sciMessageService;

    @GetMapping
    @Operation(summary = "查询")
    public R<List<SciMessage>> msgList() {
        List<SciMessage> res = this.sciMessageService.msgList();
//        System.out.println(res);
        return R.OK(res);
    }


    @PostMapping("/save")
    @Operation(summary = "保存")
    public R<SciMessage> save(HttpServletRequest request, @Validated @RequestBody SciMessage sciMessage) {
        return this.sciMessageService.saveMessage(sciMessage);
    }

    @PutMapping("/update/{status}")
    @Operation(summary = "修改")
    public R<SciMessage> update(HttpServletRequest request,@PathVariable Integer status,
                                        @Validated @RequestBody SciMessage sciMessage) {
        return sciMessageService.updateMessage(status,sciMessage);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除")
    public R<String> delete(HttpServletRequest request, @Validated @RequestBody List<String> ids) {
        if (null == ids || ids.isEmpty()) {
            return R.NG("删除失败，缺少参数");
        }
        return this.sciMessageService.deleteByIds(ids);
    }
    @DeleteMapping("/deleteQuash")
    @Operation(summary = "删除")
    public R<String> deleteQuash(HttpServletRequest request,  @Validated @RequestBody SciMessage sciMessage) {
        return this.sciMessageService.deleteByMsg(sciMessage);
    }

    @GetMapping("/recent")
    @Operation(summary = "查询")
    public R<Map<String, Object>> msgRecent() {
        Map<String, Object> res = this.sciMessageService.msgRecent();
        return R.OK(res);
    }
}
